home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Power 1997 December
/
MACPOWER-1997-12.ISO.7z
/
MACPOWER-1997-12.ISO
/
AMUG
/
PROGRAMMING
/
Raven 1.2 Examples.sit
/
Raven 1.2 Examples
/
Quill
/
Source
/
WindowProxy.cpp
< prev
next >
Wrap
Text File
|
1997-09-08
|
7KB
|
268 lines
/*
* File: WindowProxy.cpp
* Summary: A stand in for TWindow that behaves better when it's being edited.
* Written by: Jesse Jones
*
* Copyright ゥ 1996 Jesse Jones.
* For conditions of distribution and use, see copyright notice in ZTypes.h
*
* Change History (most recent first):
*
* <-> 12/24/96 JDJ Created
*/
#include "WindowProxy.h"
#include <List.h>
#include <ZAttribute.h>
#include <ZStream.h>
#include <ZUndoMgr.h>
#include "Document.h"
#include "ViewContainer.h"
// ===================================================================================
// class CWindowProxy
// ===================================================================================
static TReanimatorRegister<CWindowProxy> sWindowProxyRegistrar;
static TReanimatorRegister<CWindowProxy> sWindowRegistrar("TWindow");
bool CWindowProxy::msUseProxy = false;
//---------------------------------------------------------------
//
// CWindowProxy::~CWindowProxy
//
//---------------------------------------------------------------
CWindowProxy::~CWindowProxy()
{
// Delete the view container while we're still the right type.
this->DoDeleteSubPanes();
}
//---------------------------------------------------------------
//
// CWindowProxy::CWindowProxy ()
//
//---------------------------------------------------------------
CWindowProxy::CWindowProxy()
{
this->AddAttribute("Editing", new TAttribute(kNonPersistant));
if (mUndoContext == nil)
mUndoContext = new TUndoMgr;
msUseProxy = false;
}
//---------------------------------------------------------------
//
// CWindowProxy::CWindowProxy (SWindowInfo, MCommander*)
//
//---------------------------------------------------------------
CWindowProxy::CWindowProxy(const SWindowInfo& info, MCommander* superCommander) : TWindow(info, superCommander)
{
mOldAttributes = mAttributes;
mAttributes.hasCloseBox = true;
mAttributes.resizable = true;
mAttributes.clickThrough = true;
mAttributes.eraseOnUpdate = false;
mAttributes.hideOnSuspend = false;
mAttributes.targetable = true;
mAttributes.handleClicks = true;
mAttributes.layer = kRegularLayer;
if (mUndoContext == nil)
mUndoContext = new TUndoMgr;
this->AddAttribute("Editing", new TAttribute(kNonPersistant));
msUseProxy = false;
}
//---------------------------------------------------------------
//
// CWindowProxy::Create [static]
//
//---------------------------------------------------------------
MReanimatable* CWindowProxy::Create(MReanimatable*)
{
if (msUseProxy)
return new CWindowProxy;
else
return new TWindow;
}
//---------------------------------------------------------------
//
// CWindowProxy::HandleClick
//
//---------------------------------------------------------------
void CWindowProxy::HandleClick(const TMouseEvent& globalEvent, short partCode)
{
TRect sizeBox = mWindowPtr->portRect;
sizeBox.left = sizeBox.right - 15;
sizeBox.top = sizeBox.bottom - 15;
TPoint localPt = this->PortToLocal(this->GlobalToPort(globalEvent.GetPosition()));
if (sizeBox.Contains(localPt))
partCode = inGrow;
Inherited::HandleClick(globalEvent, partCode);
}
//---------------------------------------------------------------
//
// CWindowProxy::SetInfo
//
//---------------------------------------------------------------
void CWindowProxy::SetInfo(const SWindowInfo& info)
{
TDisableInvariant disable(this); // otherwise will get ASSERT with non-targetable windows
Inherited::SetInfo(info);
mOldAttributes = mAttributes;
mAttributes.hasCloseBox = true;
mAttributes.resizable = true;
mAttributes.clickThrough = true;
mAttributes.eraseOnUpdate = false;
mAttributes.hideOnSuspend = false;
mAttributes.targetable = true;
mAttributes.handleClicks = true;
mAttributes.layer = kRegularLayer;
}
#pragma mark ハ
//---------------------------------------------------------------
//
// CWindowProxy::Invariant
//
//---------------------------------------------------------------
void CWindowProxy::Invariant() const
{
Inherited::Invariant();
if (mSubPanes->size() > 0) {
ASSERT(mSubPanes->size() == 1);
TPane* subPane = mSubPanes->front();
ASSERT(subPane != nil);
ASSERT(dynamic_cast<CViewContainer*>(subPane) != nil);
}
}
//---------------------------------------------------------------
//
// CWindowProxy::OnStreamOut
//
//---------------------------------------------------------------
void CWindowProxy::OnStreamOut(TOutStream& stream) const
{
CWindowProxy* thisPtr = const_cast<CWindowProxy*>(this);
thisPtr->mAttributes = mOldAttributes;
try {
Inherited::OnStreamOut(stream);
thisPtr->mAttributes.hasCloseBox = true;
thisPtr->mAttributes.resizable = true;
thisPtr->mAttributes.clickThrough = true;
thisPtr->mAttributes.eraseOnUpdate = false;
thisPtr->mAttributes.hideOnSuspend = false;
thisPtr->mAttributes.targetable = true;
thisPtr->mAttributes.handleClicks = true;
thisPtr->mAttributes.layer = kRegularLayer;
} catch (...) {
thisPtr->mAttributes.hasCloseBox = true;
thisPtr->mAttributes.resizable = true;
thisPtr->mAttributes.clickThrough = true;
thisPtr->mAttributes.eraseOnUpdate = false;
thisPtr->mAttributes.hideOnSuspend = false;
thisPtr->mAttributes.targetable = true;
thisPtr->mAttributes.handleClicks = true;
thisPtr->mAttributes.layer = kRegularLayer;
throw;
}
}
//---------------------------------------------------------------
//
// CWindowProxy::OnReanimated
//
//---------------------------------------------------------------
void CWindowProxy::OnReanimated()
{
Inherited::OnReanimated();
mOldAttributes = mAttributes;
mAttributes.hasCloseBox = true;
mAttributes.resizable = true;
mAttributes.clickThrough = true;
mAttributes.eraseOnUpdate = false;
mAttributes.hideOnSuspend = false;
mAttributes.targetable = true;
mAttributes.handleClicks = true;
mAttributes.layer = kRegularLayer;
if (mUndoContext == nil)
mUndoContext = new TUndoMgr;
TDesktop::Instance()->NormalizeWindowOrder();
}
//---------------------------------------------------------------
//
// CWindowProxy::OnOpen
//
//---------------------------------------------------------------
void CWindowProxy::OnOpen()
{
Inherited::OnOpen();
this->Show();
}
//---------------------------------------------------------------
//
// CWindowProxy::DoClickInGrow
//
//---------------------------------------------------------------
void CWindowProxy::DoClickInGrow(const TMouseEvent& globalEvent)
{
TSize oldSize = this->GetSize();
Inherited::DoClickInGrow(globalEvent);
TSize newSize = this->GetSize();
if (newSize != oldSize) {
CViewContainer* container = dynamic_cast<CViewContainer*>(mSubPanes->front());
container->UpdateResource();
}
}